<template>
  <div class="validate-password">
    <el-input v-model="password" type="password" password placeholder="请输入登录密码" @keyup.native.enter="submit" />
    <el-button type="primary" @click="submit" :loading="submitLoading" :disabled="(password ?? '') === ''">确认</el-button>
  </div>
</template>

<script>
  import { validatePasswordApi } from '@/api/modules/admin'
  export default {
    props: {
      otherParams: {
        type: Object,
        default: () => ({})
      }
    },
    data () {
      return {
        password: '',
        submitLoading: false
      }
    },
    methods: {
      async submit () {
        try {
          this.submitLoading = true
          const params = {
            password: this.password,
            ...this.otherParams
          }
          const { data } = await validatePasswordApi(params)
          this.$emit('success', data, this.otherParams)
        } catch (err) {
          this.$emit('error')

        }
        this.submitLoading = false
      }
    }
  }
</script>

<style lang="less">
  .validate-password {
    max-width: 400px;
    margin: 0 auto;

    display: flex;
    align-items: center;
    justify-content: space-between;
    .el-button {
      margin-left: 24px;
    }
  }
</style>